var maxSubArray = function(arr) {
    let dpArr = []
    dpArr[0] = arr[0]
    max = arr[0]
    for (let i = 1; i < arr.length; i++) {
        if (dp[i - 1] > 0) {
            dp[i] = dp[i - 1] + arr[i]
            max = dp[i] > max ? dp[i] : max
        } else {
            dp[i] = arr[i]
        }
    }
    return max
};